package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.BlackListMapper;
import com.tanhua.dubbo.mappers.UserInfoMapper;
import com.tanhua.model.db.BlackList;
import com.tanhua.model.db.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {
    @Autowired
    private BlackListMapper blackListMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override//查询黑名单
    public IPage<UserInfo> findByPage(Long userId, Integer page, Integer pagesize) {
        //1.根据userId查询对应的黑名单列表,这里采用分页查询

        //2.先构建一个分页查询对象,将page和pagesize传入
        Page<UserInfo> pages = new Page<>(page,pagesize);
        //3.然后根据分页条件和当前的userId来查询
        return userInfoMapper.findBlackList(pages,userId);

    }

    @Override//移除黑名单
    public void delete(Long userId, String uid) {
        QueryWrapper<BlackList> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        qw.eq("black_user_id",uid);
        blackListMapper.delete(qw);
    }
}
